from flask import Flask
from flask.json.provider import DefaultJSONProvider
from flask_cors import CORS
from flask_migrate import Migrate
from flask_restful import Api
import config

from exts import db, migrate, api

from models import *

def create_app():
    app = Flask(__name__)
    app.config.from_object("config")
    
    CORS(app, origins=config.cors, supports_credentials=True)

    db.init_app(app)
    migrate.init_app(app, db)

    
    from routes.admin import AdminUser
    from routes.auth import AdminLogin
    from routes.warehouse import warehouses
    from routes.inventory import Item_api,inventory_api
    from routes.audit import audit_api
    
    api.init_app(app)

    return app